<!--
 * @Description  :
 * @Autor        : guoxi
 * @Date         : 2022-06-16 10:16:50
 * @LastEditors  : Please set LastEditors
 * @LastEditTime : 2022-08-17 22:01:36
 * @FilePath     : \rpms\src\views\project\detail\index.vue
-->
<template>
  <div v-if="!isShow">
    <el-card>
      <div class="card-wrap">
        <el-page-header :content="projectInfo.projectName" @back="handleBack" />
        <!-- <div>
          <template
            v-if="projectInfo.canAuth === 1 && projectInfo.saveStatus === '2'"
          >
            <el-button type="primary" @click="approve">审核</el-button>
            <el-button type="primary" @click="reject">驳回</el-button>
          </template>
          <template
            v-if="projectInfo.canAuth === 0 && projectInfo.saveStatus === '2'"
          >
            <el-button type="primary" @click="recall">撤回</el-button>
          </template>
        </div> -->
      </div>
    </el-card>
    <br />
    <el-card>
      <template #header>项目基本信息</template>
      <Descriptions
        :projectInfo="projectInfo"
        :isBase="false"
        :isApplication="true"
      />
    </el-card>
    <br />
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span> 流程状态</span>
          <div v-if="show5" @click="show5 = !show5" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show5 = !show5" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-if="steps && steps.length">
        <el-collapse-transition>
          <status-info :currentStep="currentStep" :steps="steps" />
        </el-collapse-transition>
      </div>
    </el-card>
    <br />
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span> 流转记录</span>
          <div v-if="show6" @click="show6 = !show6" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show6 = !show6" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show6">
        <el-collapse-transition>
          <approval-info :activities="approveRecord" />
        </el-collapse-transition>
      </div>
    </el-card>
  </div>
  <div v-else v-loading="isShow" class="empt-content"></div>
</template>

<script lang="ts" setup>
import { ref, reactive } from "vue";
import { useRouter, useRoute } from "vue-router";
import Descriptions from "./components/descriptions.vue";
import StatusInfo from "/@/components/StatusInfo/index.vue";
import ApprovalInfo from "/@/components/ApprovalInfo/index.vue";
// import WorkArea from "./components/workArea.vue";
import {
  getApproveHistory,
  getProjectInfo
  // approveProject,
  // rejectProject,
  // recallProject
} from "/@/api/project";
import { flowStatusObj } from "/@/components/StatusInfo/type";
// import { flowTypeCode } from "../create/types";
// import NotifMessage from "/@/utils/message/notification";
// import { ElMessageBox } from "element-plus";
const router = useRouter();
const route = useRoute();
const approveRecord = ref([]);
let isShow = ref(true);
let show5 = ref<boolean>(true);
let show6 = ref<boolean>(true);
const steps = ref([]);
const currentStep = ref(null);
const model = reactive({
  flowType: "2028"
});
const handleBack = () => {
  router.replace("/project/manage");
};

let projectInfo = ref(null);

const getStep = () => {
  const nodeId = route.query.nodeId ? route.query.nodeId : "ACT_010";
  steps.value = flowStatusObj[model.flowType];
  if (steps.value && steps.value.length) {
    steps.value.forEach((item, index) => {
      if (item.nodeId === nodeId) {
        currentStep.value = Number(index);
      }
    });
  }
};

const getApproveHistoryList = async () => {
  const instanceId = route.query.instanceId;
  if (instanceId) {
    const { code, data } = await getApproveHistory(instanceId);
    if (code === 200) {
      approveRecord.value = data;
    }
  }
};

const initProjectInfo = async () => {
  try {
    const queryId = route.query?.id ?? "";
    const { code, data } = queryId && (await getProjectInfo({ id: queryId }));
    if (code === 200) {
      projectInfo.value = data;
      // const emyp = data.approveTypeMaxCode + "," + data.approveTypeMinCode;
      // model.flowType = flowTypeCode[emyp];
      // console.log(projectInfo.value, "data");
      // isSaveStatus.value= projectInfo.value.
      isShow.value = false;
      getStep();
    }
  } catch (err) {
    console.log(err);
  }
};

initProjectInfo();
getApproveHistoryList();
</script>

<style lang="scss" scoped>
.empt-content {
  height: calc(100vh - 200px);
  width: 100%;
}

.card-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .header-btn {
    font-size: 14px;
    cursor: pointer;
  }
}
</style>
